package com.zxkj.commonpatrol.viewmodel;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.databinding.ObservableField;

import com.czy.basecommon.utils.base.BaseRepository;
import com.czy.basecommon.utils.base.BaseViewModel;
import com.czy.basecommon.utils.base.StateLiveData;
import com.zxkj.commonpatrol.model.response.RouteCustomInfoResponse;
import com.zxkj.commonpatrol.repoisity.AddCheckPointRepoisity;
import com.zxkj.commonpatrol.repoisity.MProfileRepoisity;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class MProfileViewModel extends BaseViewModel<MProfileRepoisity> {
     public StateLiveData<Object> save=new StateLiveData();
    public StateLiveData<Object> data=new StateLiveData();
    public HashMap<Integer,String>map=new HashMap<>();



    public MProfileViewModel(@NonNull Application application) {
        super(application);
    }

    public  void getData(String RouteInspectNo,String RouteTypeCode){
        mRepository.getData(RouteInspectNo, RouteTypeCode, new BaseRepository.MyBaseDataCallBack() {
            @Override
            public void onDataSuccessCallBack(Object o) {
                if (o!=null){
                    List<RouteCustomInfoResponse> routeCustomInfoResponse =(List<RouteCustomInfoResponse>)o;

                    data.postSuccess(o);
                }
            }

            @Override
            public void onDataFailCallBack(Object o, Object t1) {
                data.postFailure(404,(String)t1);
            }
        });

    }

    public void  SaveData(String Code, Map<String, String> values){
        List<String> datas=new ArrayList<>();
        List<String> keyCode=new ArrayList<>();
        for(Map.Entry<String, String> entry : values.entrySet()){
            String mapKey = entry.getKey();
            String mapValue = entry.getValue();
            datas.add(mapValue);
            keyCode.add(mapKey);
        }


        mRepository.Save(Code, datas, keyCode,new BaseRepository.MyBaseDataCallBack() {
            @Override
            public void onDataSuccessCallBack(Object o) {
                save.postSuccess(o);
            }

            @Override
            public void onDataFailCallBack(Object o, Object t1) {
                save.postFailure(404,(String)t1);
            }
        });


    }


}
